package leetcode121

func maxProfit(prices []int) int {
	var (
		max int = 0
		min int = 0
	)
	if len(prices) < 2 {
		return 0
	}
	min = prices[0]
	for i := 1; i < len(prices); i++ {
		min = minInt(prices[i], min)
		max = maxInt(max, prices[i]-min)
	}
	return max
}

func minInt(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
